package com.codermn.demo8;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Properties;
import java.util.Set;

/**
 * @author jxau_scf
 * @date 2021/6/27 - 17:21
 */
public class TestProperties {
    public static void main(String[] args) throws IOException {
        Properties properties = new Properties();
        properties.setProperty("username","张三");
        properties.setProperty("password","123456");
        Set<String> set = properties.stringPropertyNames();
        for (String key : set){
            String value = properties.getProperty(key);
            System.out.println("key:"+key+","+"value:"+value);
        }
        //写
        FileWriter fileWriter = new FileWriter("C:\\Users\\lenovo\\Desktop\\copy.txt");
        properties.store(fileWriter,"save data");
        fileWriter.close();
        //读
        Properties prop = new Properties();
        prop.load(new FileReader("C:\\Users\\lenovo\\Desktop\\copy.txt"));
        Set<String> set1 = prop.stringPropertyNames();
        System.out.println("读出来的数据========================");
        for (String key1 : set1){
            String value1 = properties.getProperty(key1);
            System.out.println("key1:"+key1+","+"value1:"+value1);
        }

    }
}
